package com.menhai.personmanagement.services;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.menhai.personmanagement.entity.TjWordsDirectory;
import com.menhai.personmanagement.mapper.TjWordsDirectoryMapper;
/**
 * <p>
 * 常用语目录 服务类
 * </p>
 *
 * @author shikun
 * @since 2021-11-25
 */
 @Service
public class TjWordsDirectoryService{

   @Autowired
   private TjWordsDirectoryMapper tjWordsDirectoryMapper;
  
   /**
    * 查询字典列表
    * @return
    */
   public List<Map<String,Object>> getDirectoryList(){
	   List<Map<String,Object>>  directoryList= new ArrayList<Map<String,Object>>();
	   //根节点(一级)
	   Map<String,Object> map = new HashMap<String,Object>();
	   map.put("label", "所有目录");
	   map.put("id", "root");	   
	   //查询二级列表
	   List<TjWordsDirectory> listOne = tjWordsDirectoryMapper.getDirectoryList("root");
	   List<Map<String,Object>> twoNode = new ArrayList<Map<String,Object>>();
	   for(int i=0;i<listOne.size();i++){
		   TjWordsDirectory tjWordsDirectoryTwo = listOne.get(i);
		   Map<String,Object> twoMap = new HashMap<String,Object>();
		   twoMap.put("label", listOne.get(i).getDirectoryName());
		   twoMap.put("id", listOne.get(i).getId());		
		   //查询三级列表
		   List<TjWordsDirectory> listTwo = tjWordsDirectoryMapper.getDirectoryList(tjWordsDirectoryTwo.getId());
		   List<Map<String,Object>> threeNode = new ArrayList<Map<String,Object>>();
		   for(int j=0;j<listTwo.size();j++){
			   TjWordsDirectory tjWordsDirectoryThree = listTwo.get(j);
			   Map<String,Object> threeMap = new HashMap<String,Object>();
			   threeMap.put("label", listTwo.get(j).getDirectoryName());
			   threeMap.put("id", listTwo.get(j).getId());			   
			   //查询四级列表
			   List<TjWordsDirectory> listThree = tjWordsDirectoryMapper.getDirectoryList(tjWordsDirectoryThree.getId());
			   List<Map<String,Object>> fourNode = new ArrayList<Map<String,Object>>();
			   for(int x=0;x<listThree.size();x++){
				   Map<String,Object> leaf = new HashMap<String,Object>();
				   leaf.put("label", listThree.get(x).getDirectoryName());
				   leaf.put("id", listThree.get(x).getId());
				   leaf.put("children", "");
				   fourNode.add(leaf);
			   }
			   threeMap.put("children", fourNode);
			   threeNode.add(threeMap);
		   }
		   twoMap.put("children", threeNode);
		   twoNode.add(twoMap);
	   }
	   map.put("children", twoNode);
	   directoryList.add(map);
	   return directoryList;
   }


	
}
